function chunk (arr, size = 1) {
  const bigArr = []
  let smallArr = []

  if (arr.length === 0) return bigArr

  if (size < 0) {
    size = 1
  }

  arr.forEach(item => {
    if (smallArr.length === 0) {
      bigArr.push(smallArr)
    }

    smallArr.push(item)

    if (smallArr.length === size) {
      smallArr = []
    }
  })

  return bigArr
}

// const chunk = (arr, size = 1) => {
//   const result  = []

//   for (let i = 0; i < arr.length; i+=size) {
//     result.push(arr.slice(i, i + size))
//   }

//   return result
// }

const arr = [1, 2, 3, 4, 5, 6, 7, 8]

console.log(chunk(arr, 3))


const arr = [1, 2, 3, 4, 5, 6, 7, 8]

// console.log(chunk(arr, 3))

console.log(arr.map(parseInt))
